﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoMapper;
using DTO;

namespace DAO
{
    public class HangVe_DAO
    {
        public static HangVe_DTO CreateHangVeDTO(HangVe hangve)
        {
            HangVe_DTO hangveDTO = new HangVe_DTO();
            hangveDTO.MaHangVe = hangve.MaHangVe;
            hangveDTO.TenHangVe = hangve.TenHangVe;
            return hangveDTO;
        }
        public List<HangVe_DTO> GetHangVeList()
        {
            List<HangVe_DTO> listHangVe = new List<HangVe_DTO>();
            try
            {
                QLCBDataContext context = new QLCBDataContext();
                var query = from hv in context.HangVes select hv;
                foreach (var hv in query)
                {
                    HangVe_DTO hangveDTO = CreateHangVeDTO(hv);
                    listHangVe.Add(hangveDTO);
                }
            }
            catch (System.Exception ex)
            {
                string str = ex.Message;
            }
            return listHangVe;
        }
        public static string GetTenHangVe(string maMaHangVe)
        {
            QLCBDataContext context = new QLCBDataContext();
            string query = (from hv in context.HangVes
                            where hv.MaHangVe == maMaHangVe
                            select hv.TenHangVe).ToString();
            return query;
        }
    }
}
